﻿using BellAssistant.Model.Tables;

namespace BellAssistant.Common.CommonHelper
{
    public static class LoginInfo
    {
        /// <summary>
        /// 用户名称
        /// </summary>
        public static string UserName { set; get; }
        /// <summary>
        /// 登录账户
        /// </summary>
        public static string LoginName { get; set; }
        /// <summary>
        /// 用户密码
        /// </summary>
        public static string Password { set; get; }

        /// <summary>
        /// 机构代码
        /// </summary>
        //public static string RegionCode { get; set; }


        /// <summary>
        /// 用户所属的权限组ID
        /// </summary>
        public static int GrpID { get; set; }
        
        private static UserInfo _currentUser;
        public static UserInfo CurrentUser
        {
            //set
            //{
            //    _currentUser = value;
            //    if (value != null)
            //    {
            //        LoginInfo.UserName = value.UserName;
            //        LoginInfo.Password = value.Password;
            //        LoginInfo.LoginName = value.LoginName;
            //        LoginInfo.GrpID = value.GrpID;
            //    }
            //}
            get
            {
                return _currentUser;
            }
        }

        /// <summary>
        /// 校验文本长度
        /// </summary>
        /// <param name="Info"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static bool CheckInfoLength(string Info, int Length)
        {
            int len;
            bool trueOrFalse = true;
            if (Info != null)
            {
                len = Info.Length;
                byte[] sarr = System.Text.Encoding.Default.GetBytes(Info);
                len = sarr.Length;
                if (len > Length)
                {
                    trueOrFalse = false;
                }
            }
            return trueOrFalse;
        }

        /// <summary>
        /// 计算文本长度
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int CountStrLength(string str)
        {
            int length = 0;
            if (!string.IsNullOrEmpty(str))
            {
                length = str.Length;
                byte[] sarr = System.Text.Encoding.Default.GetBytes(str);
                length = sarr.Length;
            }
            return length;
        }

        public static string GetMaxLengthInformation(string checkInfo, int length)
        {
            return checkInfo + "最大允许输入" + length + "字符(1个汉字等于2个字符)";
        }
    }
}
